/**
 * Created by Elsa on 2017/8/9.
 */
layui.define(['form', 'layer','jquery'], function(exports){
    var form = layui.form(),
        $ = layui.jquery,
        layer = layui.layer;

    form.on('submit(casegly)', function(data) {
        $.ajax({
            type: "GET",
            url: contextPath + "/user/fzr/" + $('#userid').val(),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                console.log(data);
                if(data.state == "正常"){
                    $('#nameInfo').attr('class','fa fa-unlock');
                    $('#name').attr("disabled",false);
                    $('#name').attr("class","layui-input");
                    $('#sexInfo').attr('class','fa fa-unlock');
                    $('#sex').attr("disabled",false);
                    $('#sex').attr("class","layui-input");
                    $('#usernameInfo').attr('class','fa fa-unlock');
                    $('#phone').attr("disabled",false);
                    $('#phone').attr("class","layui-input");

                    $('#changee').hide();
                    $('#changeex').show();

                    $('#sexk').hide();
                    $('#sexs').show();

                    if(data.sex == "男"){
                        $("#se option[value='男']").attr("selected", true);
                    } else if(data.sex == "女"){
                        $("#se option[value='女']").attr("selected", true);
                    }

                }else {
                    $("#all-info").html("*该用户已被禁用!");
                }

                form.render();
            },
            error: function (e) {

            }
        });

        return false;
    });

    form.on('submit(caseglyx)', function(data) {
        $(this).attr('disabled','disabled');
        var updateHeaduser = new Object();
        updateHeaduser.name = $('#name').val();
        updateHeaduser.sex = $("select[name='sex'] option:selected").val();
        updateHeaduser.userid = $('#userid').val();
        updateHeaduser.username = $('#phone').val();
        console.log(JSON.stringify(updateHeaduser));

        $.ajax({
            type:"PUT",
            url:contextPath+"/user/fzr/update",
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(updateHeaduser),
            dataType:"json",
            success:function (data) {
                console.log(data.message);
                if(data.message == "负责人用户更新成功!"){
                    layer.closeAll();
                    layer.msg('负责人用户更新成功!<br>页面将在1秒后刷新...');
                    setTimeout(function(){window.location.reload();},1000);
                } else {
                    $('#suresubmitx').attr('disabled',false);
                    layer.msg(data.message, {
                        time:false,
                        btn:"确定",
                        btnAlign: 'c'
                    });
                    $("#all-info").html("*"+data.message);
                }
            },
            error:function (e) {
            }
        });

        return false;
    });

    exports('DetailsHead', {}); //注意，这里是模块输出的核心，模块名必须和use时的模块名一致
});